package com.wt.chat.service.impl;

import com.wt.chat.cache.RedisCache;
import com.wt.chat.mapper.KefuGroupMapper;
import com.wt.chat.service.KefuGroupService;
import com.wt.chat.utils.Keys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description
 * @author: wangtao
 * @date:17:52 2019/11/29
 * @email:taow02@jumei.com
 */
@Service
public class KefuGroupServiceImpl implements KefuGroupService {

	@Autowired
	private KefuGroupMapper kefuGroupMapper;

	@Autowired
	private RedisCache redisCache;

	@Override
	public List<String> getHandleKefusByGroupId(Integer groupId) {
		String key = Keys.getGroupIdKey(groupId + "");
		List<String> handleGroupkefu = redisCache.range(key, 0, -1, String.class);
		if(handleGroupkefu == null || handleGroupkefu.isEmpty()) {
			handleGroupkefu = kefuGroupMapper.findByGroupId(groupId);
			if(handleGroupkefu != null && !handleGroupkefu.isEmpty()) {
				redisCache.pushList(key, handleGroupkefu);
			}
		}
		return handleGroupkefu;
	}

}
